package org.framework.edge.builder.application.impl;

import jakarta.annotation.Resource;
import org.framework.edge.builder.application.DockerBuildModuleRecordApplication;
import org.framework.edge.builder.application.assembler.DockerBuildModuleRecordDTOAssembler;
import org.framework.edge.builder.application.command.docker.build.module.record.*;
import org.framework.edge.builder.application.dto.DockerBuildModuleRecordDTO;
import org.framework.edge.builder.domain.model.docker.builder.module.record.DockerBuildModuleRecord;
import org.framework.edge.builder.domain.model.docker.builder.module.record.DockerBuildModuleRecordRepository;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 打包记录 
 *
 * @author Jia wei Wu
 * @date 2024/08/13 07:39 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class DockerBuildModuleRecordApplicationImpl implements DockerBuildModuleRecordApplication {

    @Resource
    DockerBuildModuleRecordRepository dockerBuildModuleRecordRepository;
    /**
     * describe 新增打包记录
     *
     * @param dockerBuildModuleRecordStoryCommand 新增打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> story(DockerBuildModuleRecordStoryCommand dockerBuildModuleRecordStoryCommand) {
        DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordStoryCommand);
        return dockerBuildModuleRecordRepository.story(dockerBuildModuleRecord);
    }
    /**
     * describe 批量新增打包记录
     *
     * @param dockerBuildModuleRecordStoryCommandList 批量新增打包记录     
     * @return {@link Result<List<DockerBuildModuleRecord>>} 打包记录新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModuleRecord>> batchStory(List<DockerBuildModuleRecordStoryCommand> dockerBuildModuleRecordStoryCommandList) {
        List<DockerBuildModuleRecord> dockerBuildModuleRecordList = dockerBuildModuleRecordStoryCommandList.stream().map( DockerBuildModuleRecordDTOAssembler.INSTANCE::toDockerBuildModuleRecord).collect(Collectors.toList());
        return dockerBuildModuleRecordRepository.batchStory(dockerBuildModuleRecordList);
    }
    /**
     * describe 更新打包记录
     *
     * @param dockerBuildModuleRecordUpdateCommand 更新打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> updateOne(DockerBuildModuleRecordUpdateCommand dockerBuildModuleRecordUpdateCommand) {
        DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordUpdateCommand);
        return dockerBuildModuleRecordRepository.story(dockerBuildModuleRecord);
    }

    /**
     * describe 查询单个打包记录
     *
     * @param dockerBuildModuleRecordQueryOneCommand 查询单个打包记录     
     * @return {@link Result<DockerBuildModuleRecordDTO>} 打包记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecordDTO> findOne(DockerBuildModuleRecordQueryOneCommand dockerBuildModuleRecordQueryOneCommand) {
        DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordQueryOneCommand);
        return dockerBuildModuleRecordRepository.findOne(dockerBuildModuleRecord).convert(DockerBuildModuleRecordDTOAssembler.INSTANCE::fromDockerBuildModuleRecord);
    }

    /**
     * describe 查询多个打包记录
     *
     * @param dockerBuildModuleRecordQueryListCommand 查询多个打包记录     
     * @return {@link Result<List<DockerBuildModuleRecordDTO>>} 打包记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModuleRecordDTO>> findList(DockerBuildModuleRecordQueryListCommand dockerBuildModuleRecordQueryListCommand) {
        DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordQueryListCommand);
        return dockerBuildModuleRecordRepository.findList(dockerBuildModuleRecord)        .convert(dockerBuildModuleRecords -> dockerBuildModuleRecords.stream().map(DockerBuildModuleRecordDTOAssembler.INSTANCE::fromDockerBuildModuleRecord).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个打包记录
     *
     * @param dockerBuildModuleRecordQueryListCommand 分页查询多个打包记录     
     * @return {@link Result<LazyPage<DockerBuildModuleRecordDTO>>} 分页打包记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<LazyPage<DockerBuildModuleRecordDTO>> findPage(int size,int current,DockerBuildModuleRecordQueryListCommand dockerBuildModuleRecordQueryListCommand) {
        DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordQueryListCommand);
        return dockerBuildModuleRecordRepository.findPage(size,current,dockerBuildModuleRecord)        .convert(page -> page.convert(DockerBuildModuleRecordDTOAssembler.INSTANCE::fromDockerBuildModuleRecord))            ;
    }

    /**
     * describe 删除打包记录
     *
     * @param dockerBuildModuleRecordRemoveCommand 删除打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> remove(DockerBuildModuleRecordRemoveCommand dockerBuildModuleRecordRemoveCommand) {
     DockerBuildModuleRecord dockerBuildModuleRecord = DockerBuildModuleRecordDTOAssembler.INSTANCE.toDockerBuildModuleRecord(dockerBuildModuleRecordRemoveCommand);
     return dockerBuildModuleRecordRepository.remove(dockerBuildModuleRecord);
    }

}